<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>JS类的创建,继承,接口实现</title>  
<script type="text/javascript" src="../src/core/jui.js"></script>
<script type="text/javascript">  
//-------------------------  
// JS类的创建,继承,接口实现  
//-------------------------  
  
// 例子1:-------------------------  
// 创建一个类  
var Person = JUI.Class('Person',{  
    // 构造函数  
    init:function(option){  
        this.name = option.name;  
    }  
    ,sayName:function() {  
        console.log(this.name);  
    }  
    ,getName:function() {  
        return this.name;  
    }  
});  
  
// 声明类实例  
var Jim = new Person({name:'Jim'});  
Jim.sayName();  
  
//例子2:-------------------------  
  
// 创建一个接口,接口里面有sayName方法  
var Act = JUI.Interface('Act',['sayName']);  
  
// 创建一个类,继承Person类,并实现Act接口  
var Man = JUI.Class('Man',{  
    init:function(option) {  
        this._super(option);// 调用父类构造函数  
        this.age = option.age;  
    }  
    ,sayAge:function() {  
        console.log(this.age);  
    }  
},Person).impl(Act);  
  
var man = new Man({name:'Tom',age:22});  
man.sayName();  
man.sayAge();  
  
//例子3:-------------------------  
// 创建接口  
var Smile = JUI.Interface('Smile', ['smile']);  
// 创建类,继承Person类,实现Act,Smile两个接口  
var Woman = JUI.Class('Woman', {  
    init:function(option) {  
        this._super(option);  
    }  
    // override  
    ,smile:function() {  
        console.log('hehe');  
    }  
    // override,重写Person类的sayName方法  
    ,sayName:function() {  
        console.log('My name is ' + this.getName());  
    }  
    // override  
    ,getName:function() {  
        // 调用父类的getName()  
        var name = this._super();  
        return '{'+name+'}';  
    }  
},Person).impl(Act,Smile);  
  
var woman = new Woman({name:'Lily'});  
woman.smile();  
woman.sayName();  
  
console.log(Jim instanceof Person);  
console.log(man instanceof Person);  
console.log(woman instanceof Person);  
console.log(woman instanceof Woman);  
</script>  
</head>  
<body>  
</body>  
</html>  